package com.huanuo.internetofthings.service.impact;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.unicorn.framework.base.base.AbstractService;
import org.unicorn.framework.core.SysCode;
import org.unicorn.framework.core.exception.PendingException;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huanuo.internetofthings.bo.impact.ImpactDeviceInfo;
import com.huanuo.internetofthings.dao.impact.ImpactDeviceInfoMapper;
import com.huanuo.internetofthings.dto.statistics.DeviceInfoPageRequestDto;

@Service
public class ImpactDeviceInfoService extends AbstractService {

	@Autowired
	private ImpactDeviceInfoMapper impactDeviceInfoMapper;

	/**
	 * 查询设备信息
	 * 
	 * @param impactDeviceStatistics
	 * @return
	 * @throws PendingException
	 */
	public ImpactDeviceInfo getImpactDeviceInfo(Long id)throws PendingException {
		try {
			return impactDeviceInfoMapper.selectByPrimaryKey(id);
		} catch (Exception e) {
			error(" 查询设备信息", e);
			throw new PendingException(SysCode.DB_ERROR, " 查询设备信息");
		}
	}
	
	
	/**
	 * 查询设备信息
	 * 
	 * @param impactDeviceStatistics
	 * @return
	 * @throws PendingException
	 */
	public ImpactDeviceInfo getImpactDeviceInfo(ImpactDeviceInfo impactDeviceInfo)throws PendingException {
		try {
			return impactDeviceInfoMapper.selectOne(impactDeviceInfo);
		} catch (Exception e) {
			error(" 查询设备信息", e);
			throw new PendingException(SysCode.DB_ERROR, " 查询设备信息");
		}
	}
	
	/**
	 * 查询设备列表信息
	 * 
	 * @param impactDeviceStatistics
	 * @return
	 * @throws PendingException
	 */
	public List<ImpactDeviceInfo> getImpactDeviceInfoList(ImpactDeviceInfo impactDeviceInfo)
			throws PendingException {
		try {
			return impactDeviceInfoMapper.selectList(impactDeviceInfo);
		} catch (Exception e) {
			error("查询设备列表信息失败", e);
			throw new PendingException(SysCode.DB_ERROR, "查询设备列表信息失败");
		}
	}
	
	/**
	 * 分页查询设备信息
	 * 
	 * @param impactDeviceStatistics
	 * @return
	 * @throws PendingException
	 */
	public PageInfo<ImpactDeviceInfo> getImpactDeviceInfoPage(DeviceInfoPageRequestDto deviceListInfoRequestDto)
			throws PendingException {
		try {
			PageHelper.startPage(deviceListInfoRequestDto.getPageNo(),deviceListInfoRequestDto.getPageSize());
			List<ImpactDeviceInfo> list=impactDeviceInfoMapper.selectList(deviceListInfoRequestDto.getImpactDeviceInfo());
			PageInfo<ImpactDeviceInfo> pageInfo = new PageInfo<>(list);
			return pageInfo;
		} catch (Exception e) {
			error("分页查询设备信息失败", e);
			throw new PendingException(SysCode.DB_ERROR, "分页查询设备信息失败");
		}
	}
}